﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public static Form2 f2 =new Form2();//常量静态全局唯一值
        private int timeN;
        private int a;
        private int b;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            timeN = 300;
            Random random = new Random();
            a = random.Next(0, 20);
            b = random.Next(0, 40);
            labela.Text = a.ToString();
            labelb.Text = b.ToString();
            timer1.Enabled = true;
            timer1.Start();
            label1.Text = "做题中。。。";
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
 
        }

        private void keyPress(object sender, KeyPressEventArgs e)
        {
            if (!(char.IsNumber(e.KeyChar))&&(e.KeyChar != (char)8)&&(e.KeyChar!=Convert.ToChar(".")))
            {
                e.Handled = true;//e.handled=true即可,无效化刚刚输入的键值
                label1.Text = "请输入数字！";
            }
            else
                label1.Text = "数字输入成功！";
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (timeN > 0)
            {
                labelTime.Text = ((timeN -= 1) / 10.0).ToString();
            }
            else
            {
                timer1.Stop();
                this.result();
            }
        }
        private void result()
        {
            try
            {
                if ((a + b) == int.Parse(textBox1.Text))
                {
                    label1.Text = "very good!";
                }
                else
                    label1.Text = "再接再厉.";
            }
            catch (Exception e)
            {
                label1.Text = "再接再厉.";
            }

        }

        private void buttonNext_Click(object sender, EventArgs e)
        {
            this.Hide();
            f2.Show();
        }

        private void Exitbutton_Click(object sender, EventArgs e)
        {
            System.Environment.Exit(0);
        }
    }
}
